// pages/commentDetails/commentDetails.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    _content:'',
    _time:'',
    _id:'',
    _title:'',
    _userid:'',
    _views:'',
    _userName:'',
    _userPic:'',
    isShow:false
  },
 
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      _content:options.content,
      _time:options.createTime,
      _id:options.id,
      _title:options.title,
      _userId:options.userId,
      _views:options.views,
      _userName:options.nickName,
      _userPic:options.avatarUrl,
      isShow:JSON.parse(options.isShow)
    })
    setTimeout(()=>{
      wx.request({
        url: `http://124.222.95.170:21311/discuss/${this.data._id}`,
        method:'PUT',
        header: {
          'Cookie': wx.getStorageSync('sessionid')
        },
      })
    },10000)
    

  },
  deleteComm(e){
    // console.log(e.currentTarget.dataset)
    let id = e.currentTarget.dataset.id
    wx.showModal({
      title:"提示",
      content:"每一条书评都是智慧的结晶，您确定删除此书评吗",
      cancelText:"保留",
      cancelColor:"#4ac29a",
      success:(res)=>{
        if(res.confirm){
          wx.request({
            url: `http://124.222.95.170:21311/discuss/${id}`,
            method:'DELETE',
            header: {
              'Cookie': wx.getStorageSync('sessionid')
            },
            success:(res)=>{
              console.log('hhhh',res)
              if(res.data.data == "删除成功"){
                wx.navigateTo({
                  url: '/pages/releaseComment/releaseComment',
                }) 
              }else{
                wx.showToast({
                  title: '删除失败,请重试',
                  icon:'none'
                })
              }
              
            }
          })
        }
        
      }
    })

  }
})